<?php

namespace App\Http\Controllers\PC\User;

use App\Http\Service\User\UserService;
use Illuminate\Http\Request;
use Session,Config;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Service\Product\ProductService;


class IndexController extends Controller
{

    private $username = '';
    private $expired_at = '';

    protected  $index = 'PC.User.index';
    protected  $set = 'PC.User.set';
    protected  $invite = 'PC.User.invite';
    private    $user;

    public function __construct(UserService $user)
    {
        $this->user = $user;
    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * 个人中心
     */
    public function index()
    {
        $title='购买记录';
        $token = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));

        $where['token'] = $token;
        $user =  new UserService();
        $info = $user->getUserInfo($where);

        $this->username = $info['data']['user']['username'];
        $this->expired_at = $info['data']['user']['expired_at'];

//        dd( $this->username,$this->expired_at);

//        $ret = new ProductService();
//        $arr =  $ret->Order($where);

//
//        if($arr['code'] == '0')
//        {
//            $data = $arr['data'];
//        }else{
//            $data = [];
//        }

        return view($this->index)->with('username',$this->username)->with('expired_at',$this->expired_at)->with('title',$title);

    }


    //  忘记密码
    public function doForgetPassword(Request $request)
    {

        $data = [];
        $data['mobile'] = $request->input('mobile');
        $data['code'] = $request->input('code');
        $data['new_pass1'] = $request->input('forget_pass');
        $data['new_pass2'] = $request->input('agin_pass');
        $ret = $this->user->updatePassword($data);
        return $ret;
    }
    
    
    
    
    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * 设置
     */
    public function set()
    {
    	$title='账号管理';
        $token = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));
        $where['token'] = $token;
        $user = new UserService();
        $arr =  $user->Setting($where);

        if($arr['code'] == '0')
        {
            $data = $arr['data'];
        }else{
            $data = [];
        }
//        dd($data);
        return view($this->set)->with('data',$data)->with('title',$title);
    }


    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     *邀请
     */
    public function invite()
    {
    	$title='邀请好友';
        return view($this->invite)->with('title',$title);
    }


    // 客服

    public function KeFuqq(Request $request)
    {
        $where = [];
        $where = $request->all();
        $where['ip'] = $_SERVER["REMOTE_ADDR"];
        $user = new UserService();
        $arr =  $user->KeFuqq($where);
    }

    //   获取客服
    public function getTeamqq()
    {
        $user = new UserService();
        $data = $user->getTeamqq();
        $qq =[];

        if($data['code'] == 0)
        {
            if(!empty($data['data']))
            {
                $qq = $data['data']['qq'];
            }
        }

//        $qq = implode(',',$qq);
//        dd($qq);

        return $qq;
    }



    public function sendCode()
    {
        echo '111111';
    }


}
